<?php
namespace app\model;
use think\Model;

class User extends Model{

  //获取当前登陆用户id
  public static function getCurrentUid(){
    $userInfo = session('userInfo');
    $result = $userInfo['id'];
    return $result;
  }

  //获取当前项目id
  public static function getCurrentProjectId(){
    $userInfo = session('userInfo');
    if($userInfo['role_id'] == 0){
      $result = 0;
    }else{
//      $res = model('ProjectRole')->where('id',$userInfo['role_id'])->find();
      $res = ProjectRole::get(['id'=>$userInfo['role_id']]);
      $result = $res['project_id'];
    }
    return $result;
  }

  //检验当前操作权限
  public static function checkHandlerPermission($permissionValue){
    $ret = false;
    if(session('userInfo.role_id') == 0){
      $ret = true;
    }else{
      if(session('userInfo.role_id') != 0){
        $res = ProjectRolePower::get(['status'=>1,'role_id'=>session('userInfo.role_id')]);
        $power_ids = $res['power_ids'];
        $power_idsArr = explode(',',$power_ids);
        $powerAll = Power::all(['status'=>1]);
        foreach($power_idsArr as $key=>$value){
          foreach($powerAll as $k=>$val){
            if($value == $val['id']){
              $permissionArr[] = $val['value'];
            }
          }
        }
      }
      if(in_array($permissionValue,$permissionArr)){
        $ret = true;
      }
    }
    return $ret;
  }



}//END